import httpsRequest from '@/assets/httpsRequest';

export default {
  namespaced: true,
  state: {
    imagesDetail: {},
    thumbnailImages: [],
  },
  actions: {
    async getImagesThumbnail({ commit }, { payload }) {
      const res = await httpsRequest({
        url: `getthumimages/${payload.detailId}`,
      });
      const { status, data = {} } = res;
      const { message = [] } = data;
      if (status === 200) {
        commit({
          type: 'setImagesThumbnail',
          payload: {
            thumbnailImages: message,
          },
        });
      }
    },
    async getImagesDetail({ commit }, { payload }) {
      const res = await httpsRequest({
        url: `getimageInfo/${payload.detailId}`,
      });
      const { status, data = {} } = res;
      const { message = [] } = data;
      if (status === 200) {
        commit({
          type: 'setImagesList',
          payload: {
            imagesDetail: message[0] || {},
          },
        });
      }
    },
  },
  mutations: {
    setImagesThumbnail(state, { payload }) {
      Object.assign(state, payload);
    },
    setImagesList(state, { payload }) {
      Object.assign(state, payload);
    },
  },
  getters: {
    formatThumbImages(state) {
      /* eslint-disable */
      state.thumbnailImages.forEach((item, index) => {
        item.src = 'http://cs-static-assets.oss-cn-beijing.aliyuncs.com/kaikeba/banner3.jpg';
        item.msrc = 'http://cs-static-assets.oss-cn-beijing.aliyuncs.com/kaikeba/suoluetu.png';
        item.w = 800; // 展示大图的宽
        item.h = 400; // 展示大图的高
        item.title = `图片${index + 1}`
        item.alt = 'images'
      });
      return state.thumbnailImages;
    },
  },
};
